#define _CRT_SECURE_NO_WARNINGS 1



#include<stdio.h>
#include<stdlib.h>


typedef struct Node
{
	int data;
	struct Node* next;
} SLNode;
void ListInit(SLNode** L)
{
	*L = (SLNode*)malloc(sizeof(SLNode));
	(*L)->next = NULL;
}
int ListLength(SLNode* L)
{
	SLNode* p = L;
	int len = 0;
	while (p->next != NULL)
	{
		p = p->next;
		len++;
	}
	return len;
}
int ListInsert(SLNode* L, int i, int x)
{
	SLNode* p = L, * q;
	int j = -1;
	while (p->next != NULL && j < i - 1)
	{
		p = p->next;
		j++;
	}
	if (j != i - 1)
		return 0;
	q = (SLNode*)malloc(sizeof(SLNode));
	q->data = x;
	q->next = p->next;
	p->next = q;
	return 1;
}
int ListDelete(SLNode* L, int i, int* x)
{
	SLNode* p = L, * s;
	int j = -1;
	while (p->next != NULL && p->next->next != NULL && j < i - 1)
	{
		p = p->next;
		j++;
	}
	if (j != i - 1)
		return 0;
	s = p->next;
	*x = s->data;
	p->next = p->next->next;
	free(s);
	return 1;
}
int ListGet(SLNode* L, int i, int* x)
{
	SLNode* p = L;
	int j = -1;
	while (p->next != NULL && j < i)
	{
		p = p->next;
		j++;
	}
	if (j != i)
		return 0;
	*x = p->data;
	return 1;
}
void ListDestroy(SLNode** L)
{
	SLNode* p = *L, * q;
	while (p != NULL)
	{
		q = p;
		p = p->next;
		free(q);
	}
	*L = NULL;
}
int main()
{
	SLNode* L;
	int i = 0, x = 0;
	ListInit(&L);
	for (i = 0; i < 10; i++)
		ListInsert(L, i, i + 1);
	ListDelete(L, 4, &x);
	for (i = 0; i < ListLength(L); i++)
	{
		ListGet(L, i, &x);
		printf("%d ", x);
	}
	ListDestroy(&L);

	return 0;
}